// pages/carmanagebox/carsearch/carsearch.js
import {
  getSearchCar,
  getSearchHistorys
} from '../../../utils/networkRequest.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchValue: "",
    carList: [],
    historys: [], //历史搜索纪录
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let self = this;
    getSearchHistorys((r) => {
      console.log(r);
      if (r.code == 0) {
        self.setData({
          historys: r.data
        })
      }
    })
  },
  //获取搜索值 
  getSearchVal: function (e) {
    this.setData({
      searchValue: e.detail.value
    })
  },

  //搜索
  onSearch: function (e) {
    debugger;
    let keywork = "";
    if (e.currentTarget.dataset.keyword) {
      keywork = e.currentTarget.dataset.keyword;
    } else {
      keywork = this.data.searchValue;
    }
    let self = this;

    getSearchCar(keywork, (r) => {

      if (!r.data[0]) {
        wx.showToast({
          icon: "none",
          title: '没有找到对应车辆',
        })
      }
      self.setData({
        carList: r.data
      })
    })
  },
  //编辑车辆
  onJieChe: function (e) {
    let item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: "../../jiechebox/main/main?qc=" + item.qcode
    })
  },
})